/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package application;

import java.io.File;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.Repository;

/**
 *
 * @author mazid
 */
public class Core {

    /**
     * @param args the command line arguments
     */
    private static final Core instance = new Core();
    private List<Class<?>> classes;
    private List<IPlugin> interfaces;
    //fonction qui return l'instance de la classe
    public static Core getInstance(){
        return instance;
    }
    public void lunch() throws InstantiationException, IllegalAccessException{
        File f = new File("../Graphe/build/classes");
        File file = new File("../Application/plugins");
        Repository<Object> rep = new Repository<>(file, Object.class );
        classes = rep.load();
        ViewManager.getInstance().init();
        
        for(Class<?> c: classes){
           // if(c.getDeclaredClasses()!=null){
                if(IPlugin.class.isAssignableFrom(c)){
                    IPlugin plugin = (IPlugin)c.newInstance();
                    ViewManager.getInstance().displayMenuBar(plugin.getMenu(), plugin.getName());
                    plugin.addTable();
                    System.out.println(plugin.getName()); 
                }
                else{
                    if(IPlugin2.class.isAssignableFrom(c)){
                        IPlugin2 plugin2 = (IPlugin2)c.newInstance();
                        plugin2.addPanelHaut();
                    }
                }
            //}
            
        }  
    }
    //pour recuperer la liste des classes chargées
    public List<Class<?>> getClasses() {
        return classes;
    }
    //fonction qui recupere les classes qui implemente l'interface IPlugin
    public List<IPlugin> getInterface(){
        for(Class<?> c:getClasses()){
            if(IPlugin.class.isAssignableFrom(c)){
                try {
                    IPlugin plugin = (IPlugin)c.newInstance();
                    interfaces.add(plugin);
                    
                } catch (InstantiationException | IllegalAccessException ex) {
                    Logger.getLogger(Core.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return interfaces;
    }
    
    //main du projet
    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        // TODO code application logic here
        getInstance().lunch();
                
    }
    
}
